package com.sino.androiddesign.test

import android.content.Context
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import android.widget.FrameLayout
import android.widget.LinearLayout
import com.sino.androiddesign.R
import com.sino.androiddesign.recyclerviewdemo.SlidingAdapter
import kotlinx.android.synthetic.main.activity_test.*

class TestActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test)


        frame1.setOnClickListener {

            val layoutParams1 = frame1.layoutParams as FrameLayout.LayoutParams
            layoutParams1.width = FrameLayout.LayoutParams.MATCH_PARENT
            layoutParams1.height = FrameLayout.LayoutParams.MATCH_PARENT
            frame1.elevation = 10f
            frame1.layoutParams = layoutParams1

            val layoutParams2 = frame2.layoutParams as FrameLayout.LayoutParams
            layoutParams2.width = 100
            layoutParams2.height = 100
            frame2.elevation =20f
            frame2.layoutParams = layoutParams2
        }

        frame2.setOnClickListener {
            val layoutParams1 = frame1.layoutParams as FrameLayout.LayoutParams
            layoutParams1.width = 100
            layoutParams1.height = 100
            frame1.elevation = 20f
            frame1.layoutParams = layoutParams1

            val layoutParams2 = frame2.layoutParams as FrameLayout.LayoutParams
            layoutParams2.width = FrameLayout.LayoutParams.MATCH_PARENT
            layoutParams2.height = FrameLayout.LayoutParams.MATCH_PARENT
            frame2.layoutParams = layoutParams2
            frame2.elevation = 10f

        }


    }
}


//class MyTestView : LinearLayout {
//
//    private lateinit var contextView: View   //内容区域
//    private lateinit var deleteView: View   //删除按钮
//
//    private var viewHeight = 0   //视图高度
//
//
//    constructor(context: Context?) : this(context, null)
//    constructor(context: Context?, attrs: AttributeSet?) : this(context!!, attrs!!, 0)
//    constructor(context: Context, attributeSet: AttributeSet, defAttrStyle: Int) : super(context, attributeSet, defAttrStyle) {
//        orientation = LinearLayout.HORIZONTAL
//    }
//
//    override fun onFinishInflate() {
//        super.onFinishInflate()
//        contextView = findViewById(R.id.test_content_tv)
//        deleteView = findViewById(R.id.test_delete_tv)
//    }
//
//    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
//        super.onMeasure(widthMeasureSpec, heightMeasureSpec)
//    }
//
//    override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
//        super.onLayout(changed, l, t, r, b)
//        deleteView.layout(contextView.measuredWidth, 0, contextView.measuredWidth + deleteView.measuredWidth, measuredHeight)
//    }
//
//
//    private var startX: Int = 0
//    private var downX: Int = 0
//
//    override fun onTouchEvent(event: MotionEvent?): Boolean {
//
//        when (event!!.action) {
//            MotionEvent.ACTION_DOWN -> {
//                startX = event.x.toInt()
//                downX = startX
//            }
//            MotionEvent.ACTION_MOVE -> {
//                var currentX = event.x.toInt()
//                var disX = currentX - startX
//
//                println("110  disx= $disX ; scrollX= $scrollX")
//
//                var abs = Math.abs(scrollX - disX)
//                println("110 abs= $abs")
//                if (abs < 0) {
//                    abs = 0
//                }
//                if (abs > deleteView.width) {
//                    abs = deleteView.width
//                }
//                scrollTo(abs, 0)
//                startX = event.x.toInt()
//            }
//            MotionEvent.ACTION_UP -> {
//                var abs = Math.abs(event.x.toInt() - downX)
//                println("110  action_up $abs")
//                if (abs > deleteView.width / 2) {
//                    scrollTo(deleteView.width, 0)
//                    postInvalidate()
//                } else {
//                    scrollTo(0, 0)
//                    postInvalidate()
//                }
//            }
//        }
//
//        return true
//    }
//}